import React, { Component } from 'react';
import store from '../../store1';
class Mycls extends Component {
    constructor() {
        super()
        // 初始化赋值
        this.state = store.getState()
        console.log('state', this.state);

        store.subscribe(() => this.setState(() => store.getState()))
    }
    render() {
        return (
            <div>
                <p>count: {this.state.reducer.count}</p>
                <p><button onClick={this.addCount}>count++</button></p>
                <p>money:{this.state.reducer1.money}</p>
                <p><button onClick={this.addMoney}>moeny++</button></p>
            </div>
        );
    };
    addCount = () => {
        // 问题? 调用一个rendcer 还是所有的reducer?
        // 当页面中派发一个action 任务的时候, 所有的reducers 都会被触发, 然后去匹配对应的action 任务,
        // 进而修改store 中的state
        store.dispatch({ type: '+', payload: 1 })
    }
    addMoney = () => {
        store.dispatch({ type: 'add' })
    }
}

export default Mycls;
